<div class="bina goodsmanager">
    <div class="nav">
        <div class="nav-li focus">商品分销</div>
        <a href="#admin/bina_user"><div class="nav-li">分销人员</div></a>
    </div>
    <hr />

    <div class="infobox">
        <div class="bina_config">
            <h4>商品分销规则
                {{#if $Cahcs.bina_buff.editing}}
                    <android:paperbutton event-click="{{'$Event.bina_buff.upload'}}">完成</android:paperbutton>
                    <android:paperbutton event-click="{{'$Event.bina_buff.cancle'}}">取消</android:paperbutton>
                {{#else}}
                    <android:paperbutton event-click="{{'$Event.bina_buff.edit'}}">修改</android:paperbutton>
                {{/if}}
            </h4>
            <div style="display:inline-block;width:50%;vertical-align: top;height:180px;">
                <h5>商品基础分销规则 </h5>
                {{#if $Cahcs.bina_buff.editing}}
                    <div>一级返利：<inputnumber value="{{$Cache.bina_buff.config.first}}" bind-input="{{'$Cache.bina_buff.new_config.first'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber></div>
                    <div>二级返利：<inputnumber value="{{$Cache.bina_buff.config.second}}" bind-input="{{'$Cache.bina_buff.new_config.second'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </div>
                    {{#if bus_info.permission.can_bina_to_third}}
                        <div>三级返利：<inputnumber value="{{$Cache.bina_buff.config.third}}" bind-input="{{'$Cache.bina_buff.new_config.third'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </div>
                    {{/if}}
                {{#else}}
                    <p>一级返利： {{#Fixed $Cache.bina_buff.config.first}}</p>
                    <p>二级返利： {{#Fixed $Cache.bina_buff.config.second}}</p>
                    {{#if bus_info.permission.can_bina_to_third}}
                        <p>三级返利： {{#Fixed $Cache.bina_buff.config.third}}</p>
                    {{/if}}
                {{/if}}
            </div>
            <div class="hr-left" style="display:inline-block;width:50%;vertical-align: top;height:180px;box-sizing:border-box;padding-left:1.2em;">
                {{#if $Cahcs.bina_buff.editing}}
                    <h5>商品高级分销规则，所需累积消费金额：
                        <inputnumber value="{{$Cache.bina_buff.config.to_senior_bina_cash}}" bind-input="{{'$Cache.bina_buff.new_config.to_senior_bina_cash'}}" min="0" loop="100" fixed="2" value-map-0.00="未设定" style="width:60px;" ></inputnumber>
                    </h5>
                    <div>一级返利：<inputnumber value="{{$Cache.bina_buff.config.senior.first}}" bind-input="{{'$Cache.bina_buff.new_config.senior.first'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber></div>
                    <div>二级返利：<inputnumber value="{{$Cache.bina_buff.config.senior.second}}" bind-input="{{'$Cache.bina_buff.new_config.senior.second'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </div>
                    {{#if bus_info.permission.can_bina_to_third}}
                        <div>三级返利：<inputnumber value="{{$Cache.bina_buff.config.senior.third}}" bind-input="{{'$Cache.bina_buff.new_config.senior.third'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </div>
                    {{/if}}
                {{#else}}
                    <h5>商品高级分销规则，所需累积消费金额：
                        {{#if $Cache.bina_buff.config.to_senior_bina_cash}}
                            ￥{{#Fixed $Cache.bina_buff.config.to_senior_bina_cash}}
                        {{#else}}
                            <i>未设定</i>
                        {{/if}}
                    </h5>
                    <p>一级返利： {{#Fixed $Cache.bina_buff.config.senior.first}}</p>
                    <p>二级返利： {{#Fixed $Cache.bina_buff.config.senior.second}}</p>
                    {{#if bus_info.permission.can_bina_to_third}}
                        <p>三级返利： {{#Fixed $Cache.bina_buff.config.senior.third}}</p>
                    {{/if}}
                {{/if}}
            </div>
            <div class="hr"></div>
            <div>
                <h4>分销商品累积购买加入永久分销的金额：</h4>
                <inputnumber style="width:240px;" value="{{bus_loginer.info.data_to_forever_bina_cash}}" bind-input="{{'bus_loginer.info.data_to_forever_bina_cash'}}" value-map-0.00="不设置自动开启永久分销权限的金额" min="0" loop="100" event-change="{{'$Event.bina.update_config'}}" fixed="2"></inputnumber>
                <p><i>用户购买分销商品的总金额累积到一定程度，会自动开启永久分销。如果改动了这个值，不会影响现有永久分销人员 </i></p> 
            </div>
            <!-- <android:input label="分销商品累积购买加入永久分销的金额" description=""></android:input> -->
        </div>
        <div class="hr"></div>
        <div class="bina_list goods_list" style="width:50%;display:inline-block;">
            <h4>分销商品列表：</h4>
            <table>
                <thead>
                    <td class="logo">缩略图</td>
                    <td class="name">名称</td>
                    <td class="method">操作</td>
                </thead>
                {{#each $Cache.bina.bina_list}}
                <tr>
                    <td><img bind-src="{{goods.preview_img_url}}?imageView/1/w/25/h/25" alt="{{goods.goods_name}}的缩略图"></td>
                    <td><a title="{{goods._id}}" href="http://{{window.location.host}}/#admin/update_goods?id={{goods._id}}">{{goods.goods_name}}</a></td>
                    <td>
                        <button event-click="{{'$Top.$Event.cancel_as_bina_goods'}}" >取消使用商品分销</button>
                        {{#if $Private.$Cache.show_setting}}
                        <button event-click="{{'$Top.$Event.close_edit_goods_bina_config'}}" style="font-weight: bold;{{goods.use_custom_bina_id?'background-color:#0058D1;color:#fff;':''}}">✕</button>
                        {{#else}}
                        <button style="{{goods.use_custom_bina_id?'background-color:#0058D1;color:#fff;':''}}" class="icon-numbered-list" event-click="{{'$Top.$Event.open_edit_goods_bina_config'}}"></button>
                        {{/if}}
                    </td>
                </tr>
                {{#> "goods_bina_config","$This",$Private.$Cache.show_setting}}
                {{/each}}
            </table>
        </div>
        <div class="goods_list" style="width:50%;display:inline-block;">
            <h4>商品列表：</h4>
            <table>
                <thead>
                    <td class="logo">缩略图</td>
                    <td class="name">名称</td>
                    <td class="method">操作</td>
                </thead>
                {{#each goods}}
                <tr>
                    <td><img bind-src="{{preview_img_url}}?imageView/1/w/25/h/25" alt="{{goods_name}}的缩略图"></td>
                    <td><a title="{{_id}}" href="{{$Top.bus_loginer.url}}/goods-details.html?id={{_id}}">{{goods_name}}</a></td>
                    <td>
                        {{#if is_bina}}
                        <i>已绑定为分销商品</i>
                        {{#else}}
                        <button event-click="{{'$Top.$Event.set_as_bina_goods'}}" >使用商品分销</button>
                        {{/if}}
                    </td>
                </tr>
                {{/each}}
            </table>

            <pagination
             id="turn-page"
             page-info="$Cache.bus.goods.page_info"
             ></pagination>
        </div>
        <br>
        <br>
    </div>
</div>
<xmp type="template" name="goods_bina_config">
    <tr>
        <td><span class="icon-arrow-up "></span></td>
        <td colspan="2" style="text-align: left;">
        <div>
            <android:switch checked="{{goods.use_custom_bina_id}}" bind-input="{{'goods.use_custom_bina_id'}}" event-change="{{'$Top.$Event.use_custom_bina_id.toggle'}}">
            是否使用独立分销规则：<b>{{goods.use_custom_bina_id?'是':'否'}}</b>
        </div>
        {{#if goods.use_custom_bina_id}}
        <div>
            <div>一级返利：<inputnumber value="{{goods_custom_bina_buff.config.first}}" bind-input="{{'goods_custom_bina_buff.config.first'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            <div>二级返利：<inputnumber value="{{goods_custom_bina_buff.config.second}}" bind-input="{{'goods_custom_bina_buff.config.second'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            {{#if $Top.bus_info.permission.can_bina_to_third}}
            <div>三级返利：<inputnumber value="{{goods_custom_bina_buff.config.third}}" bind-input="{{'goods_custom_bina_buff.config.third'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            {{/if}}
        </div>
        {{/if}}
        <hr>
        <div class="user-list-of-bina">
            <button event-click="{{'$Top.$Event.get_user_list_of_bina'}}">
            {{#if !$Private.$Cache.user_list_of_bina}}
            获取并操作
            {{#else}}
            刷新
            {{/if}}
            可进行分销的会员列表
            </button>
            <button event-click="{{'$Top.$Event.show_bina_user_map'}}">显示关系网</button>
            {{#>  "goods_bina_user_list","$Private.$Cache",$Private.$Cache.user_list_of_bina}}
        </div>
        </td>
    </tr>
    <tr>
        <td colspan="3" style="border:1px #333 solid;border-width:0 1px 1px 1px;"></td>
    </tr>
</xmp>
<xmp type="template" name="goods_bina_user_list">
    <h5>商品分销会员列表：</h5>
    <div class="add-form">
        <android:input label="用户昵称、手机号码、邮箱" value="{{user_maybe_info_to_add}}" bind-input="{{'user_maybe_info_to_add'}}"></android:input>
        <button event-click="{{'$App.$Event.add_user_to_bina'}}">添加到列表</button>
    </div>
    <table class="paper-table">
    <thead>
        <td>用户名</td>
        <td>邮箱</td>
        <td>手机</td>
    </thead>
    {{#each user_list_of_bina}}
    <tr>
        <td>{{user.info.name}}</td>
        <td>{{user.info.email}}</td>
        <td>{{user.info.mobile_phone}}</td>
    </tr>
    {{/each}}
    {{#if !user_list_of_bina.length}}
    <tr>
        <td colspan="3"><i>暂无可分销此商品的用户</i></td>
    </tr>
    {{/if}}
    </table>
</xmp>
{{#if $Cache.bina.show_bina_user_map}}
<div id="bina_user_map_frame" >
    <iframe src="about:blank" id="bina_user_map_node"></iframe>
    <div class="bina_user_map_mark"></div>
</div>
{{/if}}
<style>
    .bina .user-list-of-bina .add-form{
        height: 5.5em;
    }
    .bina .user-list-of-bina .add-form .android-input{
        display:inline-block;
        width: 70%;
    }
    #bina_user_map_frame{
        position: absolute;
        width: 100%;
        height: 100%;
        top:0;
        left: 0;
        overflow: hidden;
    }
    #bina_user_map_frame .bina_user_map_mark{
        position: absolute;
        width:100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        top:0;
        left: 0;
        z-index:31;
    }
    #bina_user_map_node{
        position: fixed;
        top: 3em;
        left: 3em;
        width: 80%;
        margin: 0 auto;
        height: 60%;
        background: red;
        z-index: 32;
    }
</style>